package fy.bean;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;

import java.util.List;

import fy.util.DBUtil;

public class Ssfwzx {
	private int id;
	private String category;
	private String title;
	private String content;
	private int homepage;
	private String author;
	private String source;
	private Date time;
	private String attachment;
	private String link;
	private String url;
	private String categoryname;
	private String phone;
	public int getPuton() {
		return puton;
	}

	private String email;
	private int puton;
	


	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	PreparedStatement statement = null;
	ResultSet rs = null;
	Connection connection = null;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public String getCategoryname() {
		return categoryname;
	}
	public void setCategoryname1(String categoryname) {
		this.categoryname = categoryname;
	}
	
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public int getHomepage() {
		return homepage;
	}

	public void setHomepage(int homepage) {
		this.homepage = homepage;
	}

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		this.source = source;
	}

	public Date getTime() {
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	public String getAttachment() {
		return attachment;
	}

	public void setAttachment(String attachment) {
		this.attachment = attachment;
	}

	public String getLink() {
		return link;
	}

	public void setLink(String link) {
		this.link = link;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}
	


	public List<Ssfwzx> findAll() {
		List<Ssfwzx> list = new ArrayList<Ssfwzx>();
		DBUtil dbUtil = new DBUtil();
		connection = dbUtil.geConnection();
		String sql = "select * from ssfwzx";
		try {

			statement = connection.prepareStatement(sql);

			rs = statement.executeQuery();
			while (rs.next()) {
				Ssfwzx ssfwzx = new Ssfwzx();
				ssfwzx.setId(rs.getInt("id"));
				ssfwzx.setTitle(rs.getString("title"));
				ssfwzx.setContent(rs.getString("content"));
				ssfwzx.setCategory(rs.getString("category"));
				ssfwzx.setHomepage(rs.getInt("homepage"));
				ssfwzx.setAuthor(rs.getString("author"));
				ssfwzx.setTime(rs.getDate("time"));
				ssfwzx.setSource(rs.getString("source"));
				ssfwzx.setAttachment(rs.getString("attachment"));
				 ssfwzx.setCategoryname1(rs.getString("categoryname"));
				list.add(ssfwzx);
			}

			System.out.println("list:" + list);

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			dbUtil.close();
		}
		return list;

	}

	public List<Ssfwzx> findAllByLb(String lbString) {
		List<Ssfwzx> list = new ArrayList<Ssfwzx>();
		DBUtil dbUtil = new DBUtil();
		connection = dbUtil.geConnection();
		String sql = "select * from ssfwzx where category =?";

		try {
			statement = connection.prepareStatement(sql);
			statement.setString(1, lbString);
			System.out.println("sql :" + sql);
			rs = statement.executeQuery();
			while (rs.next()) {
				Ssfwzx ssfwzx = new Ssfwzx();
				ssfwzx.setId(rs.getInt("id"));
				ssfwzx.setTitle(rs.getString("title"));
				ssfwzx.setContent(rs.getString("content"));
				ssfwzx.setCategory(rs.getString("category"));
				ssfwzx.setHomepage(rs.getInt("homepage"));
				ssfwzx.setAuthor(rs.getString("author"));
				ssfwzx.setTime(rs.getDate("time"));
				ssfwzx.setSource(rs.getString("source"));
				ssfwzx.setAttachment(rs.getString("attachment"));
				 ssfwzx.setCategoryname1(rs.getString("categoryname"));
				list.add(ssfwzx);
			}

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			dbUtil.close();
		}
		return list;

	}
	


	public Ssfwzx findPreNewsById(String lb, int id) {

		DBUtil dbUtil = new DBUtil();
		connection = dbUtil.geConnection();
		Ssfwzx ssfwzx = new Ssfwzx();
		String sql = "select * from ssfwzx where id = (select id from ssfwzx where category = ? and id < ? order by time desc "
				+ " order by id desc limit 1)";
		try {
			statement = connection.prepareStatement(sql);
			statement.setString(1, lb);
			statement.setInt(2, id);
			// String sql = "select * from ssfwzx where id = "+id;

			// String sql = "select * from ssfwzx where id = (select id from ssfwzx where id
			// < "+id+ " order by id desc limit 1)";

			System.out.println(sql);
			rs = statement.executeQuery();

			if (rs.next()) {

				ssfwzx.setId(rs.getInt("id"));
				ssfwzx.setTitle(rs.getString("title"));
				ssfwzx.setContent(rs.getString("content"));
				ssfwzx.setCategory(rs.getString("category"));
				ssfwzx.setHomepage(rs.getInt("homepage"));
				ssfwzx.setAuthor(rs.getString("author"));
				ssfwzx.setTime(rs.getDate("time"));
				ssfwzx.setSource(rs.getString("source"));
				ssfwzx.setAttachment(rs.getString("attachment"));
				 ssfwzx.setCategoryname1(rs.getString("categoryname"));
			}

		} catch (SQLException e) {
			// ssfwzx=null;
			e.printStackTrace();
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			dbUtil.close();
		}

		return ssfwzx;
	}

	public Ssfwzx findActiceById(String lb, int id) {

		DBUtil dbUtil = new DBUtil();
		connection = dbUtil.geConnection();
		Ssfwzx ssfwzx = new Ssfwzx();
		String sql = "select * from ssfwzx where category = ? and id = ? order by time desc ";
		try {
			statement = connection.prepareStatement(sql);
			statement.setString(1, lb);
			statement.setInt(2, id);
			// String sql = "select * from ssfwzx where id = "+id;
			// select id from ssfwzx where category = '"+lb+"' and id > "

			System.out.println(sql);
			rs = statement.executeQuery();

			if (rs.next()) {

				ssfwzx.setId(rs.getInt("id"));
				ssfwzx.setTitle(rs.getString("title"));
				ssfwzx.setContent(rs.getString("content"));
				ssfwzx.setCategory(rs.getString("category"));
				ssfwzx.setHomepage(rs.getInt("homepage"));
				ssfwzx.setAuthor(rs.getString("author"));
				ssfwzx.setTime(rs.getDate("time"));
				ssfwzx.setSource(rs.getString("source"));
				ssfwzx.setAttachment(rs.getString("attachment"));
				 ssfwzx.setCategoryname1(rs.getString("categoryname"));
			}

		} catch (SQLException e) {
			// ssfwzx=null;
			e.printStackTrace();
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			dbUtil.close();
		}
		return ssfwzx;
	}

	public Ssfwzx findNextNewsById(String lb, int id) {
		DBUtil dbUtil = new DBUtil();
		connection = dbUtil.geConnection();
		Ssfwzx ssfwzx = new Ssfwzx();
		String sql = "select * from ssfwzx where id = (select id from ssfwzx where category = ? and id > ? order by time desc "
				+ " order by id asc limit 1)";
		try {
			statement = connection.prepareStatement(sql);
			statement.setString(1, lb);
			statement.setInt(2, id);
			// String sql = "select * from ssfwzx where id = "+id;

			System.out.println(sql);

			rs = statement.executeQuery();
			if (rs.next()) {
				ssfwzx.setId(rs.getInt("id"));
				ssfwzx.setTitle(rs.getString("title"));
				ssfwzx.setContent(rs.getString("content"));
				ssfwzx.setCategory(rs.getString("category"));
				ssfwzx.setHomepage(rs.getInt("homepage"));
				ssfwzx.setAuthor(rs.getString("author"));
				ssfwzx.setTime(rs.getDate("time"));
				ssfwzx.setSource(rs.getString("source"));
				ssfwzx.setAttachment(rs.getString("attachment"));
				 ssfwzx.setCategoryname1(rs.getString("categoryname"));
			}

		} catch (SQLException e) {
			// ssfwzx=null;
			e.printStackTrace();
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			dbUtil.close();
		}
		return ssfwzx;
	}

	public boolean doAdd(String category, String title, String content, String author, String source,String attachment,String txtDate) {
		boolean add = false;
		DBUtil dbUtil = new DBUtil();
		connection = dbUtil.geConnection();
		// String sql = "select password from admin where username = " + username + "'";
		String sql = "insert into ssfwzx(category,title,content,author,source,attachment,time) values(?,?,?,?,?,?,?)";
		try {
			PreparedStatement statement = connection.prepareStatement(sql);
			statement.setString(1, category);
			statement.setString(2, title);
			statement.setString(3, content);
			statement.setString(4, author);
			statement.setString(5, source);
			statement.setString(6, attachment);
			statement.setString(7, txtDate);

			System.out.println(add);
			int i = statement.executeUpdate();
			if (i > 0) {
				add = true;
			}
			;

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			dbUtil.close();
		}
		System.out.println("return前的add：" + add);
		return add;

	}

	public boolean doUpdata(String category, String title, String content, String author,int puton,
			int homepage, String txtDate,String phone,int id) {
		boolean updata = false;
		DBUtil dbUtil = new DBUtil();
		connection = dbUtil.geConnection();
		// String sql = "select password from admin where username = " + username + "'";
		String sql = "update ssfwzx set category =?,title =?,content =?,author =?,puton=?,homepage=?,time=?,phone=? where id =?";

		try {
			PreparedStatement statement = connection.prepareStatement(sql);
			statement.setString(1, category);
			statement.setString(2, title);
			statement.setString(3, content);
			statement.setString(4, author);
			statement.setInt(5, puton);
			statement.setInt(6, homepage);
			statement.setString(7, txtDate);
			statement.setString(8, phone);
			statement.setInt(9, id);

			int i = statement.executeUpdate();
			if (i > 0) {
				updata = true;
			}
			System.out.println(updata);
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			dbUtil.close();
			
		}
		return updata;

	}

	public boolean doDel(int id) {
		boolean del = false;
		DBUtil dbUtil = new DBUtil();
		connection = dbUtil.geConnection();
		// String sql = "select password from admin where username = " + username + "'";
		String sql = "delete from ssfwzx where id =?";
		try {
			PreparedStatement statement = connection.prepareStatement(sql);

			statement.setInt(1, id);
			int i = statement.executeUpdate();
			if (i > 0) {
				del = true;
			}

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			dbUtil.close();
		}
		return del;

	}

	// 模糊查询
	public List<Ssfwzx> Proselect(String tilString) {
		List<Ssfwzx> list = new ArrayList<Ssfwzx>();
		DBUtil dbUtil = new DBUtil();
		connection = dbUtil.geConnection();
		String sql = "select * from ssfwzx where concat(id,title,content,category,author,source,time) like ?";
		connection = dbUtil.geConnection();
		try {
			PreparedStatement statement = connection.prepareStatement(sql);
			statement.setString(1, "%" + tilString + "%");
			rs = statement.executeQuery();
			while (rs.next()) {
				Ssfwzx ssfwzx = new Ssfwzx();
				ssfwzx.setId(rs.getInt("id"));
				ssfwzx.setTitle(rs.getString("title"));
				ssfwzx.setContent(rs.getString("content"));
				ssfwzx.setCategory(rs.getString("category"));
				ssfwzx.setAuthor(rs.getString("author"));
				ssfwzx.setSource(rs.getString("source"));
				ssfwzx.setTime(rs.getDate("time"));
			
				list.add(ssfwzx);
			}

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			dbUtil.close();
		}
		return list;

	}
	//模糊查询带上分页
		 public List<Ssfwzx> Proselect(String lbString,String tilString,Page page) {
		    List<Ssfwzx> list =new ArrayList<Ssfwzx>();
		    DBUtil dbUtil = new DBUtil();
		    connection = dbUtil.geConnection();
	
		    String sql ="select * from ssfwzx where category =? and concat(id,title,content,category,author,source,time,puton,categoryname) like ? order by time desc limit ?,?" ;
		    connection = dbUtil.geConnection();
		    try {
		    	PreparedStatement statement = connection.prepareStatement(sql);
		     statement.setString(1, lbString);
		     statement.setString(2,"%" + tilString + "%");
		     statement.setInt(3, page.getBeginIndex());
		     statement.setInt(4, page.getEveryPage());
		     rs = statement.executeQuery();
		     while(rs.next()) {
		    	 Ssfwzx ssfwzx = new Ssfwzx();
		    	 ssfwzx.setId(rs.getInt("id"));
		    	 ssfwzx.setTitle(rs.getString("title"));
		    	 ssfwzx.setContent(rs.getString("content"));
		    	 ssfwzx.setCategory(rs.getString("category"));
		    	 ssfwzx.setAuthor(rs.getString("author"));
		    	 ssfwzx.setSource(rs.getString("source"));
		    	 ssfwzx.setTime(rs.getDate("time"));
		    	 ssfwzx.setPuton(rs.getInt("puton"));
		    	 ssfwzx.setPhone(rs.getString("phone"));
		    	 ssfwzx.setHomepage(rs.getInt("homepage"));
		    	 ssfwzx.setCategoryname1(rs.getString("categoryname"));
				   list.add(ssfwzx);
		     }
		     
		    } catch (SQLException e) {
		     e.printStackTrace();
		    }finally {
		     if (rs != null) {
		      try {
		       rs.close();
		      } catch (SQLException e) {
		       e.printStackTrace();
		      }
		     }
		     if (statement != null) {
		      try {
		       statement.close();
		      } catch (SQLException e) {
		       e.printStackTrace();
		      }
		     }
		     if(connection != null) {
		      try {
		       connection.close();
		      } catch (SQLException e) {
		       e.printStackTrace();
		      }
		     }
		     dbUtil.close();
		    }
		    return list;
		    
		   }

	
			
		private void setPuton(int int1) {
			// TODO Auto-generated method stub
			
		}

		private void setCategoryname(String string) {
			// TODO Auto-generated method stub
			
		}



		

	public int findCountByLb(String lbString) {
		List<Ssfwzx> list = new ArrayList<Ssfwzx>();
		DBUtil dbUtil = new DBUtil();
		connection = dbUtil.geConnection();
		int count = 0;
		String sql = "select count(*) totalCount from ssfwzx where category =? and puton=1";
		try {
			PreparedStatement statement = connection.prepareStatement(sql);
			statement.setString(1, lbString);
			rs = statement.executeQuery();
			if (rs.next()) {
				count = rs.getInt("totalCount");
			}

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			dbUtil.close();
		}
		return count;

	}

	public List<Ssfwzx> findAllByLbForFY(String lbString, Page page) {
		List<Ssfwzx> list = new ArrayList<Ssfwzx>();
		DBUtil dbUtil = new DBUtil();
		connection = dbUtil.geConnection();
		String sql = "select * from ssfwzx where category =? and puton=1 order by time desc limit ?,? ";
		/* String sql = "select * from ssfwzx t order by time desc; */

		try {
			PreparedStatement statement = connection.prepareStatement(sql);
			statement.setString(1, lbString);
			statement.setInt(2, page.getBeginIndex());
			statement.setInt(3, page.getEveryPage());
			rs = statement.executeQuery();
			while (rs.next()) {
				Ssfwzx newBean = new Ssfwzx();
				newBean.setCategory(rs.getString("category"));
				newBean.setId(rs.getInt("id"));
				newBean.setTitle(rs.getString("title"));
				newBean.setContent(rs.getString("content"));
				newBean.setAuthor(rs.getString("author"));
				newBean.setSource(rs.getString("source"));
				newBean.setTime(rs.getDate("time"));
				newBean.setAttachment(rs.getString("attachment"));
				newBean.setCategoryname1(rs.getString("categoryname"));
				list.add(newBean);
			}

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			dbUtil.close();
		}
		return list;

	}

	public Ssfwzx findNewsById(int id) {
		System.out.println("run findNewsById : " + id);
		DBUtil dbUtil = new DBUtil();
		connection = dbUtil.geConnection();
		Ssfwzx ssfwzx = new Ssfwzx();
		String sql = "select * from ssfwzx where id = ?";
		try {
			PreparedStatement statement = connection.prepareStatement(sql);
			statement.setInt(1, id);
			rs = statement.executeQuery();
			if (rs.next()) {
				ssfwzx.setId(rs.getInt("id"));
				ssfwzx.setTitle(rs.getString("title"));
				ssfwzx.setContent(rs.getString("content"));
				ssfwzx.setTime(rs.getDate("time"));
				ssfwzx.setAuthor(rs.getString("author"));
				ssfwzx.setSource(rs.getString("source"));
				ssfwzx.setCategory(rs.getString("category"));
				ssfwzx.setHomepage(rs.getInt("homepage"));
				ssfwzx.setAttachment(rs.getString("attachment"));
				 ssfwzx.setCategoryname1(rs.getString("categoryname"));
				 ssfwzx.setPhone(rs.getString("phone"));
				 ssfwzx.setEmail(rs.getString("email"));

			}

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			dbUtil.close();
		}
		System.out.println("end findNewsById :" + id);
		System.out.println("phone :" + ssfwzx.getPhone());
		System.out.println("email :" + ssfwzx.getEmail());
		System.out.println("content :" + ssfwzx.getContent());
		System.out.println("time :" + ssfwzx.getTime());
		return ssfwzx;

	}

	public boolean doAdd1(String category, String title, String content, int homepage, String author, String phone,
			String email) {
		boolean add = false;
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		DBUtil dbUtil = new DBUtil();
		connection = dbUtil.geConnection();
		String sql = "insert into ssfwzx(category,title,content,homepage,author,phone,email,categoryname,time) values(?,?,?,?,?,?,?,?,?)";
		try {
			PreparedStatement statement = connection.prepareStatement(sql);
			statement.setString(1, category);
			statement.setString(2, title);
			statement.setString(3, content);
			statement.setInt(4, homepage);
			statement.setString(5, author);
			statement.setString(6, phone);
			statement.setString(7, email);
			statement.setString(8, "预约立案");
			statement.setString(9, df.format(new java.util.Date()));
			System.out.println("return后的add：" + add);
			int i = statement.executeUpdate();
			if (i > 0) {
				add = true;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			dbUtil.close();
		}
		System.out.println("return前的add：" + add);
		return add;

	}

//后台分页并模糊查询
	
	//后端分页
	 public List<Ssfwzx> findbackByLbForFY(String lbString,Page page) {
			List<Ssfwzx> list = new ArrayList<Ssfwzx>();
			DBUtil dbUtil = new DBUtil();
			connection = dbUtil.geConnection();
			String sql = "select * from ssfwzx where category =?  order by time desc limit ?,? ";
			try {
				statement = connection.prepareStatement(sql);
				statement.setString(1, lbString);
				statement.setInt(2, page.getBeginIndex());
				statement.setInt(3, page.getEveryPage());
				rs = statement.executeQuery();
				while(rs.next()) {
					Ssfwzx ssfwzx = new Ssfwzx();
					ssfwzx.setCategory(rs.getString("category"));
					ssfwzx.setId(rs.getInt("id"));
					ssfwzx.setPhone(rs.getString("phone"));
					ssfwzx.setPuton(rs.getInt("puton"));
					ssfwzx.setHomepage(rs.getInt("homepage"));
					ssfwzx.setTitle(rs.getString("title"));
					ssfwzx.setContent(rs.getString("content"));
					ssfwzx.setAuthor(rs.getString("author"));
					ssfwzx.setSource(rs.getString("source"));
					ssfwzx.setTime(rs.getDate("time"));
					ssfwzx.setAttachment(rs.getString("attachment"));
					ssfwzx.setCategoryname1(rs.getString("categoryname"));
					list.add(ssfwzx);
                  
				}
				
			} catch (SQLException e) {
				e.printStackTrace();
			}finally {
				if (rs != null) {
					try {
						rs.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				if (statement != null) {
					try {
						statement.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				if(connection != null) {
					try {
						connection.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				dbUtil.close();
			}
			return list;
			
		}
	//后端模糊查询后总数
	 public int findselectCountByLb(String lbString,String tilString) {
	 	DBUtil dbUtil = new DBUtil();
	 	connection = dbUtil.geConnection();
	 	int count = 0;
	 	String sql = "select count(*) totalCount from ssfwzx where category =? and concat(id,title,content,category,author,source,time,puton,categoryname) like ? ";
	 	try {
	 		statement = connection.prepareStatement(sql);
	 		statement.setString(1, lbString);
	 		statement.setString(2,"%" + tilString + "%");
	 		rs = statement.executeQuery();
	 		if (rs.next()) {
	 			count=rs.getInt("totalCount");
	 			System.out.print("totalCount :"+count);
	 		}
	 		
	 	} catch (SQLException e) {
	 		e.printStackTrace();
	 	}finally {
	 		if (rs != null) {
	 			try {
	 				rs.close();
	 			} catch (SQLException e) {
	 				e.printStackTrace();
	 			}
	 		}
	 		if (statement != null) {
	 			try {
	 				statement.close();
	 			} catch (SQLException e) {
	 				e.printStackTrace();
	 			}
	 		}
	 		if(connection != null) {
	 			try {
	 				connection.close();
	 			} catch (SQLException e) {
	 				e.printStackTrace();
	 			}
	 		}
	 		dbUtil.close();
	 	}
	 	return count;
	 	
	 }
	//后端查询总数
	 public int findbackCountByLb(String lbString) {
	 	DBUtil dbUtil = new DBUtil();
	 	connection = dbUtil.geConnection();
	 	int count = 0;
	 	String sql = "select count(*) totalCount from ssfwzx where category =? ";
	 	try {
	 		statement = connection.prepareStatement(sql);
	 		statement.setString(1, lbString);
	 		rs = statement.executeQuery();
	 		if (rs.next()) {
	 			count=rs.getInt("totalCount");
	 		}
	 		
	 	} catch (SQLException e) {
	 		e.printStackTrace();
	 	}finally {
	 		if (rs != null) {
	 			try {
	 				rs.close();
	 			} catch (SQLException e) {
	 				e.printStackTrace();
	 			}
	 		}
	 		if (statement != null) {
	 			try {
	 				statement.close();
	 			} catch (SQLException e) {
	 				e.printStackTrace();
	 			}
	 		}
	 		if(connection != null) {
	 			try {
	 				connection.close();
	 			} catch (SQLException e) {
	 				e.printStackTrace();
	 			}
	 		}
	 		dbUtil.close();
	 	}
	 	return count;
	 	
	 }

	 
	// 按时间顺序查找上下条
	public List<Ssfwzx> findAllByLbForPX(String lbString) {
		System.out.println("run findAllByLb " + lbString);
		List<Ssfwzx> list = new ArrayList<Ssfwzx>();
		DBUtil dbUtil = new DBUtil();
		connection = dbUtil.geConnection();
		String sql = "select * from ssfwzx where category = ? and puton=1 order by time desc";
		try {
			statement = connection.prepareStatement(sql);
			statement.setString(1, lbString);
			rs = statement.executeQuery();
			while (rs.next()) {
				Ssfwzx newsBean = new Ssfwzx();
				newsBean.setCategory(rs.getString("category"));
				newsBean.setId(rs.getInt("id"));
				newsBean.setTitle(rs.getString("title"));
				newsBean.setContent(rs.getString("content"));
				newsBean.setAuthor(rs.getString("author"));
				newsBean.setSource(rs.getString("source"));
				newsBean.setTime(rs.getDate("time"));
				newsBean.setAttachment(rs.getString("attachment"));
				 newsBean.setCategoryname1(rs.getString("categoryname"));
				list.add(newsBean);

			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			dbUtil.close();
		}
		return list;

	}

	// 查找上一页的ID
	public Ssfwzx findPreNewsById(List<Ssfwzx> listSsfwzx, int id) {
		Ssfwzx ssfwzx = null;
		for (int i = 0; i < listSsfwzx.size(); i++) {
			if (id == listSsfwzx.get(i).getId() && i != 0) {
				ssfwzx = listSsfwzx.get(i - 1);
				return ssfwzx;
			}
		}
		return ssfwzx;

	}

	public Ssfwzx findNextNewsById(List<Ssfwzx> listSsfwzx, int id) {
		Ssfwzx ssfwzx = null;
		for (int i = 0; i < listSsfwzx.size(); i++) {
			if (id == listSsfwzx.get(i).getId() && i + 1 < listSsfwzx.size()) {
				ssfwzx = listSsfwzx.get(i + 1);
				return ssfwzx;
			}
		}
		return ssfwzx;

	}
	
	public Ssfwzx findNewsById1(int id,String phone,String email) {
		System.out.println("run findNewsById : " + id);
		DBUtil dbUtil = new DBUtil();
		connection = dbUtil.geConnection();
		Ssfwzx ssfwzx = new Ssfwzx();
		String sql = "select * from ssfwzx where id = ?";
		try {
			PreparedStatement statement = connection.prepareStatement(sql);
			statement.setInt(1, id);
			rs = statement.executeQuery();
			if (rs.next()) {
				ssfwzx.setId(rs.getInt("id"));
				ssfwzx.setTitle(rs.getString("title"));
				ssfwzx.setContent(rs.getString("content"));
				ssfwzx.setTime(rs.getDate("time"));
				ssfwzx.setAuthor(rs.getString("author"));
				ssfwzx.setPhone(rs.getString("phone"));
				ssfwzx.setCategory(rs.getString("category"));
				ssfwzx.setEmail(rs.getString("email"));
				ssfwzx.setAttachment(rs.getString("attachment"));
				 ssfwzx.setCategoryname1(rs.getString("categoryname"));
				 

			}

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			dbUtil.close();
		}
		System.out.println("email:"+email);
		System.out.println("phone:"+phone);
		return ssfwzx;

	}
	

}
